﻿using Entity.CDCS;
using SqlSugar;


var db = new SqlSugarClient(new ConnectionConfig()
{
    ConnectionString = "server=rm-cn-zxu3a7366000b0so.rwlb.rds.aliyuncs.com;Database=cs;Uid=sa;Pwd=123qwe!@#;",
    DbType = DbType.MySql,
    IsAutoCloseConnection = true,
    InitKeyType = InitKeyType.Attribute
}, db =>
{
    db.Aop.OnLogExecuting = (sql, pars) =>
    {
        Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响


        //获取原生SQL推荐 5.1.4.63  性能OK
        //UtilMethods.GetNativeSql(sql,pars)

        //获取无参数化SQL 对性能有影响，特别大的SQL参数多的，调试使用
        //UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)


    };
});

#region 对话框
Console.WriteLine("是否确定生成实体？");
var str = Console.ReadKey();
if (str.Key == ConsoleKey.Enter)
{
    Console.WriteLine("同步中，请稍后...");
    db.CodeFirst.InitTables<YY>();
    db.DbFirst.IsCreateAttribute().CreateClassFile(@"【Model对应的实体存放路径】");
}
else
{
    Console.WriteLine("\r\n输入错误，已退出...");
    return;
}
Console.WriteLine("数据库结构同步完成!");
#endregion